/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is [Open Source Virtual Machine Encapsulation.].
*
* The Initial Developer of the Original Code is
* Anton Nguyen.
* Portions created by the Initial Developer are Copyright (C) 2012
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*   Anton Nguyen
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */

//-----------------------------------------------------------------------------
//  
//  Package
//  
//-----------------------------------------------------------------------------

package com.zm
{
	
	//-------------------------------------------------------------------------
	//  
	//  Imports
	//  
	//-------------------------------------------------------------------------
	
	import flash.events.Event;
	import flash.utils.getQualifiedClassName;
	
	//-------------------------------------------------------------------------
	//  
	//  Class
	//  
	//-------------------------------------------------------------------------
	
	/**
	 * Contains an error encountered by the ZombieMonkey engine.
	 */
	public class ZMErrorEvent extends Event
	{
		
		//---------------------------------------------------------------------
		//  
		//  Fields
		//  
		//---------------------------------------------------------------------
		
		/**
		 * Defines the value of the type property of a ZMErrorEvent object.
		 */
		public static const RUNTIME_ERROR:String = "runtimeError";
		
		private var _error:Error;
		private var _errorID:int;
		private var _message:String;
		private var _name:String;
		
		//---------------------------------------------------------------------
		//  
		//  Constructor Method
		//  
		//---------------------------------------------------------------------
		
		/**
		 * Constructs an ZMErrorEvent.
		 * 
		 * @param error An error object that is represented by the event object.
		 */
		public function ZMErrorEvent(error:Error)
		{
			super(RUNTIME_ERROR, false, false);
			
			_error = error;
			_errorID = error.errorID;
			_message = error.message;
			_name = error.name;
		}
		
		//---------------------------------------------------------------------
		//  
		//  Properties
		//  
		//---------------------------------------------------------------------
		
		//------------------------------
		//  error
		//------------------------------
		
		/**
		 * Contains the error object associated with the error event.
		 */
		public function get error():Error
		{
			return _error;
		}
		
		//------------------------------
		//  errorID
		//------------------------------
		
		/**
		 * Contains the reference number associated with the specific error message.
		 */
		public function get errorID():int
		{
			return _errorID;
		}
		
		/**
		 * @private
		 */
		private function set errorID(value:int):void
		{
			_errorID = value;
		}
		
		//------------------------------
		//  message
		//------------------------------
		
		/**
		 * Contains the message associated with the Error object.
		 */
		public function get message():String
		{
			return _message;
		}
		
		/**
		 * @private
		 */
		private function set message(value:String):void
		{
			_message = value;
		}
		
		//------------------------------
		//  name
		//------------------------------
		
		/**
		 * Contains the name of the Error object.
		 */
		public function get name():String
		{
			return _name;
		}
		
		/**
		 * @private
		 */
		private function set name(value:String):void
		{
			_name = value;
		}
		
		//---------------------------------------------------------------------
		//  
		//  Methods
		//  
		//---------------------------------------------------------------------
		
		override public function clone():Event
		{
			return new ZMErrorEvent(error);
		}
		
		override public function toString():String
		{
			return "[" + getQualifiedClassName(this) + " type=" + type + " error=" + error + "]";
		}
	}
}